#################################################
# CHECK THE ACCURACY OF DENOMINATOR PREDICTIONS #
#################################################
# Author: Kasia Nalewajko
# First created: 3 December 2021
# Replicated: 16 June 2024

rm(list = ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("estimatr")) install.packages("estimatr")
if (!require("modelsummary")) install.packages("modelsummary")

# LOAD DATA ---------------------------------------------------------------

load("./00 SUBMITTED/00 APSR final/04 replication_files/01 data/main.Rda")

# RUN MODELS --------------------------------------------------------------

my_prediction <- lm_robust(formula = log(all_jewish_victims+1) ~ log(allocated_jpop+1),
                           data = main)

my_prediction_controls <- lm_robust(formula = log(all_jewish_victims+1) ~ log(allocated_jpop+1) + log(pop1936+1) + synagogues_dummy + log(collabos_antijew1000+1)+ log(DHI_milipol_sum1942+1) + area_sqkm + longitude + longitudesq + latitude + latitudesq  + zone5,
                                    data = main)

even_prediction <- lm_robust(formula = log(all_jewish_victims+1) ~ log(jpop_even_distribution+1),
                             data = main)

even_prediction_controls <- lm_robust(formula = log(all_jewish_victims+1) ~ log(jpop_even_distribution+1) + log(pop1936+1) + synagogues_dummy + log(collabos_antijew1000+1)+ log(DHI_milipol_sum1942+1) + area_sqkm + longitude + longitudesq + latitude + latitudesq + zone5,
                                      data = main)

# PREVIEW -------------------------------------------------------------------

modelsummary(list(my_prediction, my_prediction_controls, even_prediction, even_prediction_controls),
             coef_omit = "ar_name|zone5",
             stars = c('*' = .1, '**' = .05, '***' = .01))

# EXPORT -------------------------------------------------------------------

modelsummary(list(my_prediction, my_prediction_controls, even_prediction, even_prediction_controls),
             stars = c('*' = .1, '**' = .05, '***' = .01),
             output = "latex",
             gof_omit = "AIC|BIC|RMSE|R2 Within|R2 Within Adj.",
             coef_omit = "ar_name|zone5",
             title = "OLS regressions of predicted and evenly-distributed values of Jews' presence",
             coef_rename = c("log(pop1936 + 1)" = "1936 population",
                             "log(collabos_antijew1000 + 1)" = "Collaborators",
                             "log(DHI_milipol_sum1942 + 1)" = "1942 state presence",
                             "synagogues_dummy" = "Synagogues",
                             "area_sqkm" = "Area size (km2)",
                             "longitude" = "Longitude",
                             "latitude" = "Latitude",
                             "longitudesq" = "Longitude (sq)",
                             "latitudesq" = "Latitude (sq)",
                             "log(allocated_jpop + 1)" = "1941 Jewish population (predicted)",
                             "log(jpop_even_distribution + 1)" = "1941 Jewish population (evenly distributed)"
             ))
